﻿using System;
using System.Web.UI;
using DevExpress.Web.ASPxMenu;
using System.Xml;
using SGRapidForm.Permission.Service.Interface;
using SGRapidForm.Common;
using DevExpress.Web.ASPxGridView;
using DevExpress.Web.ASPxEditors;
using SGRapidForm.Permission.Entity;
using System.Collections.Generic;
using DevExpress.Web.ASPxGridView;

namespace SGDemo.Permission
{
    public partial class AssociatedDepts : System.Web.UI.Page
    {
        private IPermissionService _permissionService = ServiceProxyFactory.Create<IPermissionService>("permissionservice");

        protected void Page_Load(object sender, EventArgs e)
        {
            JSManager.RegAjax(Header, this.GetType().BaseType);
        }

        /// <summary>
        /// 菜单项绑定事件 - 实现操作权限控制
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void menuHeader_ItemDataBound(object sender, MenuItemEventArgs e)
        {
            IHierarchyData itemHierarchyData = (IHierarchyData)e.Item.DataItem;
            XmlElement element = (XmlElement)itemHierarchyData.Item;
        }

        /// <summary>
        /// 自定义GridView回调重新绑定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvwList_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
        {
            gvwList.DataBind();
            gvwList.Selection.UnselectAll();//不选中任何一行
        }

        protected string ProcessDeptType(string deptType)
        {
            if (deptType == "0") { return "公司"; }
            if (deptType == "1") { return "普通部门"; }
            if (deptType == "2") { return "特殊部门"; }
            return string.Empty;
        }

        [AjaxPro.AjaxMethod]
        public bool BulkDelete(string userKeyid, string[] deptKeyids)
        {
            return _permissionService.UserDept_BulkDelete(userKeyid, deptKeyids);
        }
    }

    public class AssociatedDeptsDataSource
    {
        private IPermissionService _permissionService = ServiceProxyFactory.Create<IPermissionService>("permissionservice");

        public List<Dept> GetDeptByUserKeyid(string keyid)
        {
            return _permissionService.UserDept_GetDeptByUserKeyid(keyid);
        }
    }
}